package com.wy.controller;

import com.wy.model.Room;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * @描述
 * @创建人 wangyue
 * @创建时间2019/12/1015:00
 */
@RestController
@RequestMapping("redis")
public class RedisController {

    @Autowired
    private RedisTemplate<String,Object> redisTemplate;

    @RequestMapping("save")
    public void save(){
        Room room = new Room();
        room.setId(UUID.randomUUID().toString());
        room.setCode("1111");
        room.setPrice("12.0");
        room.setState("1");
        redisTemplate.opsForValue().set("myroom",room);
    }
    @RequestMapping("get")
    public Room get(){
        Object obj = redisTemplate.opsForValue().get("myroom");
        return (Room)obj;
    }
}
